package com.mc.mcgoweb.utils.redis;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.mc.common.base.BaseResponse;
import com.mc.common.base.ResultUtil;
import com.mc.common.exception.RedisException;
import com.mc.common.redis.Impl.RedisCache;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 测试reids
 */
@SpringBootApplication
@Controller
@RequestMapping("/mc")
@Slf4j
public class RedisController {
    @Autowired
    private RedisCache redisCache;
    //为什么ObjectMapper可以注入不用加@Component，这个类springboot中有一个相当于APPCONFIG的注册
    @Autowired
    ObjectMapper objectMapper;


    @GetMapping("/redisPut")
    @ResponseBody
    public BaseResponse redisPut() throws RedisException {
        ObjectMapper copy = objectMapper.copy();
        //json转对象
//        objectMapper.convertValue();
//        //对象转json
//        String json = objectMapper.writeValueAsString(user1);
        redisCache.put("redis1", "测试redis");
        System.out.println(redisCache.get("redis1"));
        log.info("测试reids...111");
        return ResultUtil.getSuccessResultData(redisCache.get("redis1"));
    }


}